package cn.com.fone.modules.admin.common.controller;

import cn.com.fone.modules.admin.common.domain.CacheQueryEntiry;
import cn.com.fone.modules.admin.common.service.QueryCacheService;
import cn.com.fone.modules.admin.common.utils.PageUtils;
import com.alibaba.fastjson.JSONArray;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/common/query/cache")
public class QueryCacheController extends BaseController {

    private String prefix = "common/util/";

    @Autowired
    private QueryCacheService queryCacheService;

    @RequiresPermissions("common:query:cache")
    @GetMapping("")
    String cache(Model model) {
        return prefix + "/cache";
    }

    @GetMapping("/list")
    @ResponseBody
    public JSONArray list() {
        PageUtils pageUtils = null;
        // 查询列表数据
        List<CacheQueryEntiry> cacheList = queryCacheService.queryCaches("");
        JSONArray respJsonArray = new JSONArray();
        respJsonArray.addAll(cacheList);
        return respJsonArray;
    }
}
